'''
@author: Rocio
'''
class Memory:
    memory = {}
    #pid: process id --> process
    def load(self, pid, prog):
        self.memory[pid] = prog
        
    def unload(self, pid):
        del self.memory[pid]

    def read(self, pc):
        pid = pc[0]
        instr_number = pc[1]
        process = self.memory[pid]
        
        if process == None or instr_number >= len(process.code) :
            return None
        else:   
            return process.code[instr_number]
    
    def __repr__(self):
        return 'memory%s'%(self.memory)
        
